import Page
from Page import Personal
from Base.Base import Base
from selenium.webdriver.common.by import By


class PersonaAccountselectPage(Base):
    """
    账户切换界面
    """

    def __init__(self, driver):
        Base.__init__(self, driver)

        # 左侧的home键
        self.account_home_btn = (By.XPATH, Personal.RESOURCE_ID.format("ivHome"))

        # 左侧的返回键
        self.account_back_btn = (By.XPATH, Personal.RESOURCE_ID.format('ivBack'))

        # 账户标题
        self.account_title_text = (By.XPATH, Personal.RESOURCE_ID.format("textView8"))

        # 用户头像
        self.account_list_user_avatar_img = (By.XPATH, Personal.account_user_avatar_img.format(""))

        # 用户选择账户边框
        self.account_list_user_frame_icon = (By.XPATH, Personal.account_user_select_img.format(""))

        # 用户性别
        self.account_list_user_gender_icon = (By.XPATH, Personal.account_user_gender_icon.format(""))

        # 用户名称
        self.account_list_user_name_text = (By.XPATH, Personal.account_user_name_text.format(""))

        # 无账户提示
        self.account_no_user_tip_text = (By.XPATH, Personal.RESOURCE_ID.format("tv_tip_no_other_user"))

    def click_home(self):
        """
        点击左侧的home键

        :return:None
        """
        self.click_element(self.account_home_btn)

    def click_back(self):
        """
        点击左侧的back键

        :return:None
        """
        self.click_element(self.account_back_btn)

    def get_title(self):
        """
        获取账户页标题

        :return:获取元素
        """
        return self.find_element_o(self.account_title_text)

    def get_list_user_avatar(self, index=1):
        """
        获取账户页用户头像

        :return:获取元素
        """
        self.account_list_user_avatar_img = (By.XPATH, Personal.account_user_avatar_img.format(index))
        return self.find_element_o(self.account_list_user_avatar_img)

    def get_list_user_gender(self, index=1):
        """
        获取用户性别

        :return:获取元素
        """
        self.account_list_user_gender_icon = (By.XPATH, Personal.account_user_gender_icon.format(index))
        return self.find_element_o(self.account_list_user_gender_icon)

    def get_list_user_name(self, index=1):
        """
        获取账户页用户名称

        :return:获取元素
        """
        self.account_list_user_name_text = (By.XPATH, Personal.account_user_name_text.format(index))
        return self.find_element_o(self.account_list_user_name_text)

    def click_list_user_frame(self, index=1):
        """
        点击账户边框

        :return:None
        """
        self.account_list_user_frame_icon = (By.XPATH, Personal.account_user_select_img.format(index))
        self.click_element(self.account_list_user_frame_icon)

    def click_list_user_name(self, index=1):
        """
        点击账户名称

        :return:None
        """
        self.account_list_user_name_text = (By.XPATH, Personal.account_user_name_text.format(index))
        self.click_element(self.account_list_user_name_text)

    def is_display_personal_account(self):
        """
        是否进入账户切换界面

        :return: bool
        """
        return self.is_display(self.account_title_text)

    def is_display_personal_users(self):
        """
        是否含有账户

        :return: bool
        """
        return self.is_display(self.account_no_user_tip_text)